          SUBROUTINE (AT.ID,AT.DATA,DOCS.PRD,SREC)
** Version# 15.0001[1] - 08/04/2013 - 09:20am - TSMITH - eclipse

*** Subroutine: EMAIL.ATD.S005
*-------------------------------------------------------------------------*
*** Activity trigger subroutine for Email of Order Entry Docs in an HTML
*** format.
*-------------------------------------------------------------------------*
*** AT.ID     - Activity trigger ID (found in ENTITY.TRIGER field 1) (IN)
*** AT.DATA 2 - CN;     Entity ID                                    (IN)
*** AT.DATA 3 - BR;     Entity Branch                                (IN)
*** AT.DATA 4 - OID;    Order ID                                     (IN)
*** AT.DATA 5 - GEN;    Order Generation                             (IN)
*** AT.DATA 6 - INV;    Invoice Number                               (IN)
*** AT.DATA 7 - STATUS; Current Status of Generation                 (IN)
*** DOCS.PRD  - Set flag if Document is produced (Email Sent)        (OUT)
*** SREC      - Template array to store default settings for entity  (IN)
***             email setup
*-------------------------------------------------------------------------*
          * When coming from a java process, printer.id is not accurate
          * and it's not needed when logging information about e-mails
          * so we are just going to clear it out to prevent bad data
          * from going into the log.
          IF JAVA.PROC$ THEN
             PRINTER.ID = ""
          END
          PASSER     = RAISE(RAISE(SREC<6>))
          PASSER<10> = YES        ;* Flag that email.send will not send
          PASSER<11> = YES        ;* Flag to not prompt user with screen
          PASSER<18> = '.html'
          PASSER<19> = 'HTML'
          PASSER<21> = AT.DATA<4>:'.':LED(12)<1,AT.DATA<5>>

          COMMENTS   = PASSER<14> ;* Additional comments.

          EM.DATA    = ''         ;* Initialize
          EM.DATA<1> = AT.DATA<2,2> ;* CN Bill-To
          EM.DATA<2> = AT.DATA<2,1> ;* CN Ship-To
          EM.DATA<3> = AT.DATA<3>   ;* Branch
          EM.DATA<4> = AT.DATA<4> ;* OID
          EM.DATA<5> = AT.DATA<5> ;* GEN
          EM.DATA<6> = AT.DATA<7> ;* Status

          OID        = EM.DATA<4>
          GEN        = EM.DATA<5>
          OSTAT      = EM.DATA<6>

          * Check if the order status is an invoice and that we have
          * more than one invoice to print.
          OID.CT = DCOUNT(AT.DATA<13>,VM)

          IF OSTAT = 'I' AND OID.CT > 1 THEN
             * Eclipse forms batch print of invoices is a special case
             * you can't really select this as HTML for eclipse forms
             * but we added the code for backwards compat
             EMAIL.EF.BATCH.INV PASSER,AT.DATA,EM.DATA,DOCS.PRD
             RETURN
          END
          *** Depending on status, set subject of email
          IF PASSER<5> = '' THEN
             EMAIL.SET.SUBJECT 'S',OID,GEN,OSTAT,SUBJECT,ATT.NAME
             PASSER<5> = SUBJECT ;* Email Subject
          END

          *** Create the HTML email document - returned in E.BODY
          E.BODY  = ''
          SOE.MBX.ORDER.HTML OID,GEN,OSTAT,HTML.BODY,AT.ID

          COMMENTS = RAISE(RAISE(COMMENTS))
          CMT.CT = DCOUNT(COMMENTS,AM)
          *** Add line breaks to comments
          FOR JJ = 1 TO CMT.CT
             COMMENTS<JJ> := '<br>'
          NEXT JJ

          *** Replace space with nonbreak spaces so that indents and
          *** other funny formatting will be replicated correctly
          UT.REP.STR COMMENTS,' ','&nbsp;'


          * If we are sending this as an attachment, pass it to email
          * data get as an attachment instead of a body, otherwise
          * it shows up in the body no matter what.
          IF PASSER<9> THEN
             E.BODY = COMMENTS:AM:HTML.BODY
             E.ATTACH = ''
          END ELSE
             E.ATTACH = HTML.BODY
             E.BODY   = ''
             CONVERT CHAR(10) TO AM IN E.ATTACH
             CONVERT CHAR(13) TO '' IN E.ATTACH
          END

          *** Send the email
          EM.ERRS = ''
          EMAIL.DATA.GET EM.DATA,PASSER,E.BODY,E.ATTACH,EM.ERRS
          IF NOT(EM.ERRS) THEN DOCS.PRD = YES

          RETURN
*-------------------------------------------------------------------------*
!TSMITH~08/04/13~09:20
